﻿using System;
using System.Windows;
using System.Windows.Controls;
using MyFloridaHouse.libSvMassDataReport.Reports;
using MyFloridaHouse.libSvOpenDistricts.DataService;
using System.ComponentModel;


namespace MyFloridaHouse.SilverlightMassDataReport
{
    public partial class MainPage : UserControl, INotifyPropertyChanged
    {

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        // set up an interface to our data services
		//private ServiceDAL serviceDAL = new ServiceDAL(App.Current.Host.Source);
		//Todo: Refactor all occurrances of: serviceDAL = new ServiceDAL(appCurrentHostSource); appCurrentHostSource is no longer needed.
		private ServiceDAL serviceDAL = new ServiceDAL();

        // define the windows in our application
        private ACSDistrictSummary _reportACSDistrictSummary;
        public ACSDistrictSummary reportACSDistrictSummary
        {
            get { return _reportACSDistrictSummary; }
            set
            {
                if (_reportACSDistrictSummary != value)
                {
                    _reportACSDistrictSummary = value;
                    NotifyPropertyChanged("reportACSDistrictSummary");
                }
            }
        }


        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }


        private void MainPage_Loaded(object sender, RoutedEventArgs args)
        {
            try
            {
                reportACSDistrictSummary = new ACSDistrictSummary(App.Current.Host.Source, ChildwindowStackpanel);
                LayoutRoot.DataContext = reportACSDistrictSummary;

            }
            catch (Exception e)
            {
                //todo: Need to log this error and give the user something more than a system error message
                MessageBox.Show("Error during initialization " + e.ToString());

            }
        }

        private void OnComboDistrictOpened(object sender, EventArgs e)
        {
            reportACSDistrictSummary.LoadDistrictList();
        }
    }
}
